<?php

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select');

include(JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'zipcodekey.php');
include(JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'zipcode.php');
?>
<script type="text/javascript">
	Joomla.submitbutton = function(task)
	{
		if (task == 'bakery.cancel' || document.formvalidator.isValid(document.id('bakery-form')))
		{
			<?php echo $this->form->getField('description')->save(); ?>
			Joomla.submitform(task, document.getElementById('bakery-form'));
		}
	}

	var zipcode_data = <?php echo $zipcode_json ?>;
	
	jQuery(document).ready(function(){
		jQuery('#jform_zipcode').typeahead({
		  	source: <?php echo $zipcode_key ?>,
		  	onselect: function(value) { 
				var city = zipcode_data[value].City;
				var states = zipcode_data[value].Code;
				jQuery("#jform_zipcodecity").val(city);
				jQuery("#jform_zipcodestates").val(states);
			}
		})
	})
</script>

<form action="<?php echo JRoute::_('index.php?option=com_bakerys&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="bakery-form" class="form-validate">
	<div class="row-fluid">

		<div class="span10 form-horizontal">

	<fieldset>		
		<div class="tab-content">
			<div class="tab-pane active" id="details">
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('location_name'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('location_name'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('alias'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('alias'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('phone'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('phone'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('fax'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('fax'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('address'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('address'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('zipcode'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('zipcode'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('zipcodecity'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('zipcodecity'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('zipcodestates'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('zipcodestates'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('image'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('image'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('location_user'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('location_user'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('ordering'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('ordering'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('description'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('description'); ?></div>
				</div>
				
			</div>

			<input type="hidden" name="task" value="" />
			<?php echo JHtml::_('form.token'); ?>
		</div>
		</div>
		<!-- End Bakery -->
		<!-- Begin Sidebar -->
		<div class="span2">
			<h4><?php echo JText::_('JDETAILS');?></h4>
			<hr />
			<fieldset class="form-vertical">
				
				<div class="control-group">
					<div class="control-label">
						<?php echo $this->form->getLabel('state'); ?>
					</div>
					<div class="controls">
						<?php echo $this->form->getInput('state'); ?>
					</div>
				</div>

				<div class="control-group">
					<div class="control-label">
						<?php echo $this->form->getLabel('access'); ?>
					</div>
					<div class="controls">
						<?php echo $this->form->getInput('access'); ?>
					</div>
				</div>
				
			</fieldset>
		</div>
		<!-- End Sidebar -->
</form>

<script src='<?php echo JUri::root(true)."/media/com_bakerys/js/bootstrap-typeahead.js" ?>' type='text/javascript'></script>
